package cs2340.quarterblack.wheresmystuff;

import android.annotation.TargetApi;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
	
	

	/**
	 * creates the main activity page
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_tabs);
		// Show the Up button in the action bar.
		//setupActionBar();
		TabHost tabHost = getTabHost();
		
		// Android tab
		Intent lostItem = new Intent().setClass(this, LostItem.class);
		TabSpec tabSpecLost = tabHost
		  .newTabSpec("Lost")
		  .setIndicator("Lost")
		  .setContent(lostItem);
		// add all tabs 
		tabHost.addTab(tabSpecLost);
		
		Intent foundItem = new Intent().setClass(this, FoundItem.class);
		TabSpec tabSpecFound = tabHost.newTabSpec("Found").setIndicator("Found").setContent(foundItem);
		
		tabHost.addTab(tabSpecFound);
		
		Intent searchItem = new Intent().setClass(this, SearchItem.class);
		TabSpec tabSpecSearch= tabHost.newTabSpec("Search").setIndicator("Search").setContent(searchItem);
		
		tabHost.addTab(tabSpecSearch);
 
		//set Windows tab as default (zero based)
		tabHost.setCurrentTab(0);
	}

	/**
	 * Set up the {@link android.app.ActionBar}, if the API is available.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}
	/**
	 * Inflates the options menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		if(Model.getAccount().getAdmin() == "false")
		{
			getMenuInflater().inflate(R.menu.main, menu);
		}
		else
		{
			getMenuInflater().inflate(R.menu.admin_main, menu);
		}
		return true;
	}
	/**
	 * specifies the actions associated with each item in the options menu
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			//FLAG_ACTIVITY_CLEAR_TOP
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		case R.id.action_logout:
			Intent homepage = new Intent(MainActivity.this,LoginPage.class);
			homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			MainActivity.this.startActivity(homepage);
			return true;
		case R.id.action_admin:
			Intent adminPage = new Intent(MainActivity.this,AdminOptions.class);
			MainActivity.this.startActivity(adminPage);
			return true;
		case R.id.action_settings:
			Intent settings = new Intent(MainActivity.this,SettingsPage.class);
			MainActivity.this.startActivity(settings);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

}